package net.dodoman.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class Obj2File {
	private static File file = new File("E:/tmp");

	public static void main(String[] args) throws Exception {
		if (file.exists()) {
			file.delete();
			file = new java.io.File("E:/tmp");
		}
		ser();
		unser();
	}

	private static void ser() throws Exception {
		FileOutputStream fos = new FileOutputStream(file);
		ObjectOutputStream s = new ObjectOutputStream(fos);
		s.writeObject("aabc");
		s.writeObject("奇怪");
		s.writeObject(new Date());
		s.flush();
	}

	@SuppressWarnings("unused")
	private static void unser() throws Exception {
		// 从文件中反序列化 string 对象和 date 对象
		FileInputStream in = new FileInputStream(file);
		ObjectInputStream s = new ObjectInputStream(in);
		String today = (String) s.readObject();
		String qiguai = (String) s.readObject();
		Date date = (Date) s.readObject();
		System.out.println();
	}

}
